<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <!--    <div class="table-page-search-wrapper">-->
    <!--      <a-form layout="inline">-->
    <!--        <a-row :gutter="24">-->

    <!--          &lt;!&ndash;          <a-col :md="6" :sm="8">&ndash;&gt;-->
    <!--          &lt;!&ndash;            <a-form-item label="栏目">&ndash;&gt;-->
    <!--          &lt;!&ndash;              &lt;!&ndash; <j-dict-select-tag v-model="queryParam.channelId" :triggerChange="false" dictCode="cms_channel"/> &ndash;&gt;&ndash;&gt;-->
    <!--          &lt;!&ndash;              <j-category-select :triggerChange="false" pid="cms_channel_tree" pcode="cms_channel_tree"  v-model="queryParam.channelId"/>&ndash;&gt;-->
    <!--          &lt;!&ndash;            </a-form-item>&ndash;&gt;-->
    <!--          &lt;!&ndash;          </a-col>&ndash;&gt;-->
    <!--          <a-col :md="6" :sm="8">-->
    <!--            <a-form-item label="标题">-->
    <!--              <j-input v-model="queryParam.title" placeholder="请输入标题"></j-input>-->
    <!--            </a-form-item>-->
    <!--          </a-col>-->
    <!--          <template v-if="toggleSearchStatus">-->
    <!--          </template>-->
    <!--          <a-col :md="6" :sm="8">-->
    <!--            <span class="table-page-search-submitButtons" style="float: left;overflow: hidden;">-->
    <!--              <a-button icon="search" type="primary" @click="searchQuery">查询</a-button>-->
    <!--              <a-button icon="reload" style="margin-left: 8px" type="primary" @click="searchReset">重置</a-button>-->
    <!--              &lt;!&ndash;              <a @click="handleToggleSearch" style="margin-left: 8px">&ndash;&gt;-->
    <!--              &lt;!&ndash;                {{ toggleSearchStatus ? '收起' : '展开' }}&ndash;&gt;-->
    <!--              &lt;!&ndash;                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>&ndash;&gt;-->
    <!--              &lt;!&ndash;              </a>&ndash;&gt;-->
    <!--            </span>-->
    <!--          </a-col>-->

    <!--        </a-row>-->
    <!--      </a-form>-->
    <!--    </div>-->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button icon="plus" type="primary" @click="openAdd()">新增</a-button>
      <a-button @click="searchReset" icon="reload" style="margin-left: 8px">刷新数据</a-button>
      <!--      <a-button type="primary" icon="download" @click="handleExportXls('内容')">导出</a-button>-->
      <!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
      <!--        <a-button type="primary" icon="import">导入</a-button>-->
      <!--      </a-upload>-->
      <!--      <a-dropdown v-if="selectedRowKeys.length > 0">-->
      <!--        <a-menu slot="overlay">-->
      <!--          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>-->
      <!--        </a-menu>-->
      <!--        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>-->
      <!--      </a-dropdown>-->
    </div>

    <!-- table区域-begin -->
    <div>
      <!--      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">-->
      <!--        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项-->
      <!--        <a style="margin-left: 24px" @click="onClearSelected">清空</a>-->
      <!--      </div>-->

      <a-table
        ref="table"
        :columns="columns"
        :dataSource="dataSource"
        :loading="loading"
        :pagination="ipagination"
        bordered
        rowKey="id"
        size="middle"
        @change="handleTableChange">

        <!--        <template slot="originUrl" slot-scope="text, record">-->
        <!--          <span data-clipboard-action="copy" class="copyLink" :data-clipboard-text="text" @click="copyLink">{{ text}}</span>-->
        <!--        </template>-->
        <span slot="action" slot-scope="text, record">
          <a-button style="margin-right: 10px" type="primary" @click="handleEdit(record)">
            编辑
          </a-button>
            <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
              <a-button>
                删除
              </a-button>
            </a-popconfirm>
        </span>
        <span slot="originUrl" slot-scope="text, record">
<!--          <a :href="record.originUrl" class="form-title" style="" target="_blank">-->
          <!--            {{ text }}-->
          <!--          </a>-->
          <a class="form-title" @click="openLink(record)">{{ text }}</a>
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
        <trend-add-edit ref="modalForm" @ok="modalFormOk"></trend-add-edit>

  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JInput from '@/components/jeecg/JInput.vue'
import pick from 'lodash.pick'
import Vue from 'vue'
import QRCode from 'qrcodejs2'  // 引入qrcode
import JCategorySelect from '@/components/jeecg/JCategorySelect'
import TrendAddEdit from '@views/dataVisualization/components/trendAddEdit'

export default {
  name: 'CmsArticleZXList',
  mixins: [JeecgListMixin],
  components: {
    TrendAddEdit,
    JInput,
    JCategorySelect
  },
  data() {
    return {
      description: '内容管理页面',
      // 表头
      columns: [

        /*{
             title: '录入部门',
             align:"center",
             dataIndex: 'departId'
            },*/

        // {
        //   title: '栏目',
        //   align:"center",
        //   dataIndex: 'channelId',
        //   ellipsis: true,
        // },
        {
          title: '年份',
          align: 'center',
          dataIndex: 'year',
          width: 100
        },
        // {
        //   title: '短标题',
        //   align:"center",
        //   dataIndex: 'shortTitle',
        //   ellipsis: true,
        // },

        {
          title: '能源消费总量（万吨）',
          align: 'center',
          dataIndex: 'totalEnergyConsumption',
          // children: [
          //   {
          //     title: '数据（tce）',
          //     dataIndex: 'totalEnergyConsumption',
          //     width: 120,
          //     align: 'center',
          //   },
          //   {
          //     title: '同比（%）',
          //     dataIndex: 'totalEnergyConsumptionYoy',
          //     width: 120,
          //     align: 'center',
          //   },
          // ],
        },
        {
          title: '碳排放总量（万吨）',
          align: 'center',
          dataIndex: 'totalCarbonEmissions',
          // children: [
          //   {
          //     title: '数据（tco2）',
          //     dataIndex: 'totalCarbonEmissions',
          //     width: 120,
          //     align: 'center',
          //   },
          //   {
          //     title: '同比（%）',
          //     dataIndex: 'totalCarbonEmissionsYoy',
          //     width: 120,
          //     align: 'center',
          //   },
          // ],
        },
        {
          title: '能耗强度',
          align: 'center',
          title: '数据（tce/万元）',
          dataIndex: 'energyConsumptionIntensity',
          // children: [
          //   {
          //     title: '数据（tce/万元）',
          //     dataIndex: 'energyConsumptionIntensity',
          //     width: 120,
          //     align: 'center',
          //   },
          //   {
          //     title: '同比（%）',
          //     dataIndex: 'energyConsumptionIntensityYoy',
          //     width: 120,
          //     align: 'center',
          //   },
          // ],
        },
        {
          title: '碳排放强度',
          align: 'center',
          title: '数据（tco2/万元）',
          dataIndex: 'carbonEmissionIntensity',
          // children: [
          //   {
          //     title: '数据（tco2/万元）',
          //     dataIndex: 'carbonEmissionIntensity',
          //     width: 120,
          //     align: 'center',
          //   },
          //   {
          //     title: '同比（%）',
          //     dataIndex: 'carbonEmissionIntensityYoy',
          //     width: 120,
          //     align: 'center',
          //   },
          // ],
        },
        // {
        //   title: '外链链接',
        //   align:"center",
        //   dataIndex: 'originUrl',
        //   scopedSlots: {
        //     customRender: 'originUrl'
        //   }
        //   //scopedSlots: { customRender: 'originUrl' },
        // },

        // {
        //   title: '有效日期',
        //   align:"center",
        //   dataIndex: 'validDate'
        // },

        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: 200,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/carbon/carbonOverviewYearData/list?areaCode=021',
        delete: '/carbon/carbonOverviewYearData/delete',
        deleteBatch: '/cxm/cmsArticle/deleteBatch',
        exportXlsUrl: 'cxm/cmsArticle/exportXls',
        importExcelUrl: 'cxm/cmsArticle/importExcel'
      }
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  mounted() {
  },
  methods: {
    handleQrCode(record) {
      this.$nextTick(() => {
        const codeHtml = document.getElementById(record.id)
        if (codeHtml != null) {
          codeHtml.innerHTML = ''
          let qr = new QRCode(codeHtml, {
            width: 150,
            height: 150, // 高度
            text: record.originUrl // 二维码内容
            // render: 'canvas' // 设置渲染方式（有两种方式 table和canvas，默认是canvas）
            // background: '#f0f',
            // foreground: '#ff0'
          })
        }
      })
    },
    handleEdit: function(record) {
      this.$refs.modalForm.edit(record)
      this.$refs.modalForm.title = '编辑'
      this.$refs.modalForm.disableSubmit = false
    },
    openAdd() {
      this.$refs.modalForm.edit()
      this.$refs.modalForm.title = '新增'
      this.$refs.modalForm.disableSubmit = false
    },
    copyLink(data) {
      const that = this
      let clipboard = new this.clipboard('.copyLink', {
        text: function() {
          return data.originUrl
        }
      })
      clipboard.on('success', () => {
        that.$message.success('复制成功')
        clipboard.destroy()
      })
      clipboard.on('error', () => {
        that.$message.success('复制失败')
        clipboard.destroy()
      })
    },
    openLink(data) {
      const that = this
      let link = data.originUrl
      console.log(link)
      window.open(link, '_blank')
    }
  }
}
</script>
<style lang="stylus" scoped>
.form-title {
  color: #595959 !important;

  &:hover {
    text-decoration: underline;
  }
}
</style>